package com.gexiaobao.pigeon.ui.view

import android.view.View
import androidx.viewpager2.widget.ViewPager2
import kotlin.math.abs

/**
 * @Author      : hxw
 * @Date        : 2024/9/20 17:22
 * @Describe    :
 */
class GalleryPageTransformer : ViewPager2.PageTransformer {
    override fun transformPage(page: View, position: Float) {
        val absPos = abs(position)

        // 设置透明度和缩放
        when {
            absPos >= 1 -> {
                page.alpha = 0f
            }

            absPos == 0f -> {
                page.alpha = 1f
                page.scaleX = 1.0f
                page.scaleY = 1.0f
            }

            else -> {
                page.alpha = 1 - absPos
                val scaleFactor = 0.75f + (1 - absPos) * 0.25f // 当前页面稍微放大
                page.scaleX = scaleFactor
                page.scaleY = scaleFactor
            }
        }

        // 设置位置
        page.translationX = -position * page.width
    }
}